<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--<a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div style="height: 100%">
      <a-tabs default-active-key="1" :animated="false" @change="callback" style=" height: 100%">
        <a-tab-pane v-for="item in tab " :key="item.key" :tab="item.title">
          <a-spin :spinning="loading">
            <!--:rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"-->
            <a-table
              ref="table"
              size="middle"
              :scroll="{x:true}"
              bordered
              rowKey="id"
              :columns="columns"
              :dataSource="data"
              :pagination="false"
              :loading="loading"
              class="j-table-force-nowrap"
              @change="handleTableChange">
              <span slot="action" slot-scope="text, record">
                <a @click="add(record)">新增子级</a>
                <a-divider type="vertical" />
                <a @click="handleEdit(record)">编辑</a>
                <a-divider type="vertical" />
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </span>
            </a-table>
          </a-spin>
        </a-tab-pane>
      </a-tabs>
    </div>
    <gh-supplychain-material-type-form ref="modalForm" @ok="modalFormOk"></gh-supplychain-material-type-form>
  </a-card>
</template>

<script>
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction } from '@/api/manage'
  import GhSupplychainMaterialTypeForm from './modules/GhSupplychainMaterialTypeForm'

  export default {
    name: 'materialTypeList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      GhSupplychainMaterialTypeForm
    },
    data () {
      return {
        description: '材料类型表管理页面',
        tab: [
          {
            key: 1,
            title: '主要项目'
          },{
            key: 2,
            title: '辅要项目'
          },{
            key: 3,
            title: '赠品项目'
          }
        ],
        columns: [
          /*{
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
          },*/
          {
            title:'材料类型名称',
            align:"center",
            key: 'materialTypeName',
            dataIndex: 'materialTypeName',
            width: 200
          },
          {
            title:'种类',
            align:"center",
            dataIndex: 'materialTypeClassifyName',
            key: 'materialTypeClassifyName'
          },
          /*{
            title:'创建人',
            align:"center",
            dataIndex: 'createBy',
            key: 'createBy'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
            key: 'createTime'
          },
          {
            title:'描述',
            align:"center",
            dataIndex: 'remark',
            key: 'remark'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }*/
        ],
        url: {
          list: "/ghSupplychainMaterialType/list",
          add: "ghSupplychainMaterialType/add",
          delete: "/ghSupplychainMaterialType/delete",
          deleteBatch: "/ghSupplychainMaterialType/deleteBatch",
          exportXlsUrl: "/ghSupplychainMaterialType/exportXls",
          importExcelUrl: "/ghSupplychainMaterialType/importExcel",
        },
        params: {
          parentId: '',
          materialType: '',
          materialTypeName: '',
          remark: '',
        },
        loading: true,
        data: [],
        materialType: 1,
        dictOptions:{},
        superFieldList:[
          { type:'string', value:'materialTypeName', text:'材料类型名称', dictCode:'' },
          { type:'string', value:'remark', text:'描述', dictCode:''},
          { type:'int', value:'delFlag', text:'删除状态（0：未删除，1：已删除）', dictCode:'' }
        ],
      }
    },
    mounted() {
      this.loadData();
    },
    methods: {
      callback(key) {
        this.materialType = key;
        this.loadData();
      },
      loadData() {
        getAction(this.url.list, {
          materialType: this.materialType
        }).then(res => {
            if(res.success) {
              this.data = res.result;
            }
        }).finally(() => {
          this.loading = false;
        });
      },
      handleTableChange() {
        this.loadData();
      },
      modalFormOk() {
        this.loadData();
      },
      handleAdd() {
        this.$refs.modalForm.visible = true;
        this.$refs.modalForm.title = "新增";
        this.$refs.modalForm.add('', this.materialType);
      },
      handleEdit(record) {
        this.$refs.modalForm.visible = true;
        this.$refs.modalForm.title = "编辑";
        this.$refs.modalForm.edit(record);
      },
      add(r) {
        this.$refs.modalForm.visible = true;
        this.$refs.modalForm.title = "新增";
        this.$refs.modalForm.add(r.id, r.materialType);
      },
    }
  }
</script>
<style>
</style>